﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;
public partial class HumanManage_Staff_list_add : System.Web.UI.Page
{
   Db List = new Db();
        BindDrowDownList list = new BindDrowDownList();
        public  string fjkey;
        public string showjg;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["username"] == null)
            {
                this.Response.Write("<script language=javascript>alert('登陆超时！');window.parent.location = '../main_d.aspx'</script>");
                return;

            }
            fjkey = Session["FjKey"].ToString();
            if (!Page.IsPostBack)
            {
                BindAttribute();
            }
            if (!IsPostBack)
            {
                string sql_down_WenHua = "select * from qp_hr_SysData where  type='1'";
                list.Bind_DropDownList_nothing(WenHua, sql_down_WenHua, "name", "name");

                string sql_down_RenCaiFenLei = "select * from qp_hr_SysData where  type='27'";
                list.Bind_DropDownList_nothing(RenCaiFenLei, sql_down_RenCaiFenLei, "name", "name");


                string sql_down_RenCaiDengJi = "select * from qp_hr_SysData where  type='16'";
                list.Bind_DropDownList_nothing(RenCaiDengJi, sql_down_RenCaiDengJi, "name", "name");

                string sql_down_YgGongZ = "select * from qp_hr_SysData where  type='47'";
                list.Bind_DropDownList_nothing(YgGongZ, sql_down_YgGongZ, "name", "name");

                string sql_down_YgGong = "select * from qp_hr_SysData where  type='57'";
                list.Bind_DropDownList_nothing(drpzhiweileibie, sql_down_YgGong, "name", "name");


                Random g = new Random();
                string rad = g.Next(10000).ToString();
                Number.Text = "" + System.DateTime.Now.Year.ToString() + "" + System.DateTime.Now.Month.ToString() + "" + System.DateTime.Now.Day.ToString() + "" + System.DateTime.Now.Hour.ToString() + "" + System.DateTime.Now.Minute.ToString() + "" + System.DateTime.Now.Second.ToString() + "" + System.DateTime.Now.Millisecond.ToString() + "" + rad + "";
            }


            string SQL_yz = "select  * from qp_hr_SysFieldDIY where type='17'  order by PaiXun asc";
            OleDbDataReader NewReader_yz = List.GetList(SQL_yz);
            showjg = null;
            if (NewReader_yz.Read())
            {
                string SQL_mx = "select  * from qp_hr_SysFieldDIY where type='17'  order by PaiXun asc";

                OleDbDataReader NewReader_mx = List.GetList(SQL_mx);

                int glTMP1 = 0;

                showjg += "<tr> <td align=center bgcolor=#efefef class=cpx12hei colspan=4 height=26 width=33%><div align=center><strong>用户自定义字段</strong></div> </td> </tr>";
                // showjg += "<tr> ";
                while (NewReader_mx.Read())
                {

                    showjg += " <tr> <td align=right bgcolor=#cccccc class=cpx12hei height=17 nowrap=nowrap width=17%>" + NewReader_mx["Name"] + "：</td> <td bgcolor=#efefef class=cpx12hei height=17 width=33% colspan=3>" + NewReader_mx["s_str"] + "" + Request.Form["" + NewReader_mx["Number"] + ""] + "" + NewReader_mx["l_str"] + "</td></tr>";
                    glTMP1 = glTMP1 + 1;
                    if (glTMP1 == 1)
                    {
                        // showjg += "</tr><tr>";
                        glTMP1 = 0;
                    }
                }

                NewReader_mx.Close();
            }

            BindDroList();
        }
        public void BindAttribute()
        {

            YinPinBM.Attributes.Add("readonly", "readonly");
            DaoGangRQ.Attributes.Add("readonly", "readonly");
          
            Button1.Attributes["onclick"] = "javascript:return chknull();";

            Button4.Attributes["onclick"] = "javascript:return checkForm();";
            Button3.Attributes["onclick"] = "javascript:return delfj();";
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("peoplelydj.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            string SQL_Check_worknum = "select * from qp_hr_Staff where GongHao='" + List.GetFormatStr(GongHao.Text) + "'";
            OleDbDataReader MyReader_worknum = List.GetList(SQL_Check_worknum);
            if (MyReader_worknum.Read())
            {
                this.Response.Write("<script language=javascript>alert('工号重复！');</script>");
                return;
            }
            MyReader_worknum.Close();


            //上传文件
            string strBaseLocation = Server.MapPath("StaffPhoto/");
            string TruePath = string.Empty;
            string Temp1 = string.Empty;

            if (File1.PostedFile.ContentLength != 0)
            {
                //获得文件全名
                string fileName = System.IO.Path.GetFileName(File1.PostedFile.FileName);
                //获得扩展名
                string rightName = System.IO.Path.GetExtension(fileName);

                string str = Session["FjKey"].ToString();
                if (!List.StrIFInStr(rightName, str))
                {

                    this.Response.Write("<script language=javascript>alert('上传照片错误！允许上传格式为" + Session["FjKey"].ToString() + "');</script>");
                    return;

                }//如果没有包含，就提示错误

                Random g = new Random();
                string rad = g.Next(10000).ToString();
                Temp1 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + rad;
                File1.PostedFile.SaveAs(strBaseLocation + Temp1 + rightName);

                TruePath = Temp1 + rightName;  //获得随即文件名

                string sql_insert1 = "insert into qp_hr_Staff (KaiHu,ZhangHao,Shgx,Gzjl,Xxjl,Number,GongHao,XingMing,XingBie,HunYin,ChuSheng,JiGuan,MinZhu,JianKan,ZhengZhi,ShenFen,GongZuoShiJian,GongZuoNianXian,WenHua,BiYe,ZhuanYe,BiYeShiJian,SuoXueWaiYu,WaiYu,ZhangWo,JiSuanJiDj,RenCaiFenLei,RenCaiDengJi,SuoHuoZhenShu,JiaoYuJIanLi,TeChang,AiHao,Email,LianXiDiZhi,LianXIDianHua,YouBian,ShenGao,TiZhong,XueXing,GongZuoYQ,DaoGangRQ,YinPinBMId,YinPinBM,YinPinZW,YgGongZ,XiangPian,BeiZhu,KeyFile,ShuJuLaiYuan,Zhiwu,ZhiCheng,JbGongZ,YgZhuangTai,Username,Realname,Unit,UnitId,Respon,ResponId,NowTimes,zhiweileibie) values ('" + List.GetFormatStr(KaiHu.Text) + "','" + List.GetFormatStr(ZhangHao.Text) + "','" + List.GetFormatStr(Shgx.Text) + "','" + List.GetFormatStr(Gzjl.Text) + "','" + List.GetFormatStr(Xxjl.Text) + "','" + List.GetFormatStr(Number.Text) + "','" + List.GetFormatStr(GongHao.Text) + "','" + List.GetFormatStr(XingMing.Text) + "','" + List.GetFormatStr(XingBie.SelectedValue) + "','" + List.GetFormatStr(HunYin.SelectedValue) + "','" + List.GetFormatStr(ChuSheng.Text) + "','" + List.GetFormatStr(JiGuan.Text) + "','" + List.GetFormatStr(MinZhu.Text) + "','" + List.GetFormatStr(JianKan.Text) + "','" + List.GetFormatStr(ZhengZhi.Text) + "','" + List.GetFormatStr(ShenFen.Text) + "','" + List.GetFormatStr(GongZuoShiJian.Text) + "','" + List.GetFormatStr(GongZuoNianXian.Text) + "','" + List.GetFormatStr(WenHua.SelectedValue) + "','" + List.GetFormatStr(BiYe.Text) + "','" + List.GetFormatStr(ZhuanYe.Text) + "','" + List.GetFormatStr(BiYeShiJian.Text) + "','" + List.GetFormatStr(SuoXueWaiYu.Text) + "','" + List.GetFormatStr(WaiYu.Text) + "','" + List.GetFormatStr(ZhangWo.Text) + "','" + List.GetFormatStr(JiSuanJiDj.Text) + "','" + List.GetFormatStr(RenCaiFenLei.SelectedValue) + "','" + List.GetFormatStr(RenCaiDengJi.SelectedValue) + "','" + List.GetFormatStr(SuoHuoZhenShu.Text) + "','" + List.GetFormatStr(JiaoYuJIanLi.Text) + "','" + List.GetFormatStr(TeChang.Text) + "','" + List.GetFormatStr(AiHao.Text) + "','" + List.GetFormatStr(Email.Text) + "','" + List.GetFormatStr(LianXiDiZhi.Text) + "','" + List.GetFormatStr(LianXIDianHua.Text) + "','" + List.GetFormatStr(YouBian.Text) + "','" + List.GetFormatStr(ShenGao.Text) + "','" + List.GetFormatStr(TiZhong.Text) + "','" + List.GetFormatStr(XueXing.Text) + "','" + List.GetFormatStr(GongZuoYQ.Text) + "','" + List.GetFormatStr(DaoGangRQ.Text) + "','" + List.GetFormatStr(YinPinBMId.Text) + "','" + List.GetFormatStr(YinPinBM.Text) + "','" + List.GetFormatStr(YinPinZW.Text) + "','" + List.GetFormatStr(YgGongZ.SelectedValue) + "','" + TruePath + "','" + List.GetFormatStr(BeiZhu.Text) + "','" + List.GetFormatStr(Number.Text) + "','人事管理','" + List.GetFormatStr(Zhiwu.Text) + "','" + List.GetFormatStr(ZhiCheng.Text) + "','" + List.GetFormatStr(JbGongZ.Text) + "','" + YgZhuangTai.SelectedValue + "','" + this.Session["Username"] + "','" + this.Session["Realname"] + "','" + this.Session["GzdwName"] + "','" + this.Session["GzdwId"] + "','" + this.Session["Respon"] + "','" + this.Session["ResponId"] + "','" + System.DateTime.Now.ToString() + "','" + this.drpzhiweileibie.SelectedValue + "')";
                List.ExeSql(sql_insert1);
            }
            else
            {
                string sql_insert1 = "insert into qp_hr_Staff (KaiHu,ZhangHao,Shgx,Gzjl,Xxjl,Number,GongHao,XingMing,XingBie,HunYin,ChuSheng,JiGuan,MinZhu,JianKan,ZhengZhi,ShenFen,GongZuoShiJian,GongZuoNianXian,WenHua,BiYe,ZhuanYe,BiYeShiJian,SuoXueWaiYu,WaiYu,ZhangWo,JiSuanJiDj,RenCaiFenLei,RenCaiDengJi,SuoHuoZhenShu,JiaoYuJIanLi,TeChang,AiHao,Email,LianXiDiZhi,LianXIDianHua,YouBian,ShenGao,TiZhong,XueXing,GongZuoYQ,DaoGangRQ,YinPinBMId,YinPinBM,YinPinZW,YgGongZ,XiangPian,BeiZhu,KeyFile,ShuJuLaiYuan,Zhiwu,ZhiCheng,JbGongZ,YgZhuangTai,Username,Realname,Unit,UnitId,Respon,ResponId,NowTimes,zhiweileibie) values ('" + List.GetFormatStr(KaiHu.Text) + "','" + List.GetFormatStr(ZhangHao.Text) + "','" + List.GetFormatStr(Shgx.Text) + "','" + List.GetFormatStr(Gzjl.Text) + "','" + List.GetFormatStr(Xxjl.Text) + "','" + List.GetFormatStr(Number.Text) + "','" + List.GetFormatStr(GongHao.Text) + "','" + List.GetFormatStr(XingMing.Text) + "','" + List.GetFormatStr(XingBie.SelectedValue) + "','" + List.GetFormatStr(HunYin.SelectedValue) + "','" + List.GetFormatStr(ChuSheng.Text) + "','" + List.GetFormatStr(JiGuan.Text) + "','" + List.GetFormatStr(MinZhu.Text) + "','" + List.GetFormatStr(JianKan.Text) + "','" + List.GetFormatStr(ZhengZhi.Text) + "','" + List.GetFormatStr(ShenFen.Text) + "','" + List.GetFormatStr(GongZuoShiJian.Text) + "','" + List.GetFormatStr(GongZuoNianXian.Text) + "','" + List.GetFormatStr(WenHua.SelectedValue) + "','" + List.GetFormatStr(BiYe.Text) + "','" + List.GetFormatStr(ZhuanYe.Text) + "','" + List.GetFormatStr(BiYeShiJian.Text) + "','" + List.GetFormatStr(SuoXueWaiYu.Text) + "','" + List.GetFormatStr(WaiYu.Text) + "','" + List.GetFormatStr(ZhangWo.Text) + "','" + List.GetFormatStr(JiSuanJiDj.Text) + "','" + List.GetFormatStr(RenCaiFenLei.SelectedValue) + "','" + List.GetFormatStr(RenCaiDengJi.SelectedValue) + "','" + List.GetFormatStr(SuoHuoZhenShu.Text) + "','" + List.GetFormatStr(JiaoYuJIanLi.Text) + "','" + List.GetFormatStr(TeChang.Text) + "','" + List.GetFormatStr(AiHao.Text) + "','" + List.GetFormatStr(Email.Text) + "','" + List.GetFormatStr(LianXiDiZhi.Text) + "','" + List.GetFormatStr(LianXIDianHua.Text) + "','" + List.GetFormatStr(YouBian.Text) + "','" + List.GetFormatStr(ShenGao.Text) + "','" + List.GetFormatStr(TiZhong.Text) + "','" + List.GetFormatStr(XueXing.Text) + "','" + List.GetFormatStr(GongZuoYQ.Text) + "','" + List.GetFormatStr(DaoGangRQ.Text) + "','" + List.GetFormatStr(YinPinBMId.Text) + "','" + List.GetFormatStr(YinPinBM.Text) + "','" + List.GetFormatStr(YinPinZW.Text) + "','" + List.GetFormatStr(YgGongZ.SelectedValue) + "','nothing.jpg','" + List.GetFormatStr(BeiZhu.Text) + "','" + List.GetFormatStr(Number.Text) + "','人事管理','" + List.GetFormatStr(Zhiwu.Text) + "','" + List.GetFormatStr(ZhiCheng.Text) + "','" + List.GetFormatStr(JbGongZ.Text) + "','" + YgZhuangTai.SelectedValue + "','" + this.Session["Username"] + "','" + this.Session["Realname"] + "','" + this.Session["GzdwName"] + "','" + this.Session["GzdwId"] + "','" + this.Session["Respon"] + "','" + this.Session["ResponId"] + "','" + System.DateTime.Now.ToString() + "','" + this.drpzhiweileibie.SelectedValue + "')";
                List.ExeSql(sql_insert1);
            }



            string SQL_yz = "select  * from qp_hr_SysFieldDIY where type='17'  order by PaiXun asc";
            OleDbDataReader NewReader_yz = List.GetList(SQL_yz);
            if (NewReader_yz.Read())
            {
                string SQL_mx = "select  * from qp_hr_SysFieldDIY where type='17'  order by PaiXun asc";
                OleDbDataReader NewReader_mx = List.GetList(SQL_mx);
                while (NewReader_mx.Read())
                {
                    string SQL_i = "insert qp_hr_SysFieldDIYAdd (Number,Name,showBl,textbox,s_str,l_str,PaiXun,type,ivalue,keyfile) values('" + NewReader_mx["Number"] + "','" + NewReader_mx["Name"] + "','" + NewReader_mx["showBl"] + "','" + NewReader_mx["textbox"] + "','" + NewReader_mx["s_str"] + "','" + NewReader_mx["l_str"] + "','" + NewReader_mx["PaiXun"] + "','" + NewReader_mx["type"] + "','" + Request.Form["" + NewReader_mx["Number"] + ""] + "','" + Number.Text + "')";
                    List.ExeSql(SQL_i);
                }
                NewReader_mx.Close();
            }

            NewReader_yz.Close();


            List.InsertLog("新增人事管理[" + XingMing.Text + "]", "人事管理");

            this.Response.Write("<script language=javascript>alert('提交成功！');window.opener.location.reload();window.close();</script>");

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            //上传文件
            string strBaseLocation = Server.MapPath("Staff/");
            string TruePath = string.Empty;
            string Temp1 = string.Empty;

            if (uploadFile.PostedFile.ContentLength != 0)
            {
                //获得文件全名
                string fileName = System.IO.Path.GetFileName(uploadFile.PostedFile.FileName);
                //获得扩展名
                string rightName = System.IO.Path.GetExtension(fileName);

                string str = Session["FjKey"].ToString();
                if (!List.StrIFInStr(rightName, str))
                {

                    this.Response.Write("<script language=javascript>alert('上传文件错误！允许上传格式为" + Session["FjKey"].ToString() + "');</script>");
                    return;

                }//如果没有包含，就提示错误


                Random g = new Random();
                string rad = g.Next(10000).ToString();
                Temp1 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + rad;
                uploadFile.PostedFile.SaveAs(strBaseLocation + Temp1 + rightName);
                TruePath = Temp1 + rightName;  //获得随即文件名


                string sql_insert_file = "insert into qp_hr_fileupload   (Name,NewName,KeyField) values ('" + fileName + "','HumanManage/Staff/" + TruePath + "','" + Number.Text + "')";
                List.ExeSql(sql_insert_file);
                //Response.Write(sql_insert_file);


                List.InsertLog("上传附件[" + fileName + "]", "人事管理");
                BindDroList();
            }
        }

        public void BindDroList()
        {
            //附件列表
            string sql_down_1 = "select * from qp_hr_fileupload where KeyField='" + Number.Text + "'";
            list.Bind_DropDownList_nothing(fjlb, sql_down_1, "NewName", "Name");
        }


    }
